import {crmLeadsStarAPI} from "@/api/crm/leads.js";
import {crmCustomerStarAPI} from "@/api/crm/customer.js";
import {crmContactsStarAPI} from "@/api/crm/contacts.js";
import {crmBusinessStarAPI} from "@/api/crm/business.js";
import {ElMessage} from "element-plus";

/**
 * 切换关注状态
 * @param index
 * @param status
 */
export function toggleStar(data, crmType) {
  const request = {
    leads: crmLeadsStarAPI,
    customer: crmCustomerStarAPI,
    contacts: crmContactsStarAPI,
    business: crmBusinessStarAPI
  }[crmType]

  console.log("request", request)
  console.log("request", data)
  const params = {}
  params[`id`] = data[`${crmType}Id`]

  request(params).then(() => {
    ElMessage.success({message: data.star > 0 ? '取消关注成功' : '关注成功'})
    data.star = data.star > 0 ? 0 : 1
  }).catch((r) => {
    console.log("r", r)
  })
}